<template>
  <div class="app-container">
    <el-form :model="config" ref="form" size="small"  :rules="rules" :inline="true" label-width="120px">
        <el-row>
            <el-form-item label="首付款比率" prop="firstRatio">
            <el-input-number v-model="form.firstRatio" :min="1"/>
            </el-form-item>
        </el-row>
        <el-row>
            <el-form-item label="二期款比率" prop="secondRatio">
            <el-input-number v-model="form.secondRatio" :min="1"/>
            </el-form-item>
        </el-row>
        <!-- <el-row>
            <el-form-item label="抽成比率" prop="pullLayer">
            <el-input-number v-model="form.pullLayer" :min="0"/>
            </el-form-item>
        </el-row> -->
        <el-row>
            <el-form-item label="提现手续费比率" prop="withdrawalRatio">
            <el-input-number v-model="form.withdrawalRatio" :min="0"/>
            </el-form-item>
        </el-row>
        <el-form-item>
        <el-button type="primary" size="medium"  v-hasPermi="['ratio:index:edit']" @click="updateKey">修改</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script setup name="ratio">
 import { getConfigByKeys, updateByKeys } from "@/api/main/common";
    const { proxy } = getCurrentInstance();
    const data = reactive({
    form: {},
    rules: {
                    user: [
                { required: true, message: "状态不能为空", trigger: "change" }
                ],
                 rule: [
                { required: true, message: "状态不能为空", trigger: "change" }
                ]
    }
  });
  const { form, rules } = toRefs(data);

  function getKey(){
    getConfigByKeys("firstRatio,secondRatio,withdrawalRatio,pullLayer").then(res=>{
        form.value=res.data
         console.log(form.value1)
    })
  }
  
  function updateKey(){
    updateByKeys(form.value).then(res=>{
        proxy.$modal.msgSuccess("修改成功");
    })
  }
    
    function formatAmount(event) {
//   // 获取当前输入值
//   let value = event.target.value;
  
//   // 允许输入的正则表达式：仅允许数字和最多两位小数
//   const regex = /^\d*\.?\d{0,2}$/;

//   if (!regex.test(value)) {
//     // 如果不匹配，则从当前值中移除最后一个字符
//     value = value.substring(0, value.length - 1);
//   }

//   // 更新绑定的模型值为经过处理的值
//   form.value.firstRatio = value;
}
  getKey()
</script>
